﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Milan.Diagnostics;
using Milan.Deploy;

namespace Milan.Deploy
{
	/// <summary>
	/// Class for a simple console application.
	/// </summary>
	public class SimpleConsole : Application, IDisposable
	{
		public SimpleConsole(string[] args, string statuServer = null, string packageFile = null)
			: base(args)
		{
			log.Start();
			// Do a check for a later version.
			log.DisplayLine("Checking for a new version...");
			Client client = new Client();
			client.ForceUpdateThisProgram();
#if !DEBUG
			// Run the upgrade service
			if (packageFile != null)
			{
				if (File.Exists(packageFile))
				{
					Package package = Package.Load(packageFile);
					m_newVersionScanner = new NewVersionScanner(this, new Client(package));
					this.RunService(m_newVersionScanner, Type.BackgroundWorker, TriggerType.RunAlways);
				}
			}
#endif
			this.RunService(new Milan.Deploy.Reporter(this), Type.BackgroundWorker, TriggerType.RunAlways);
		}
#if !DEBUG
		private NewVersionScanner m_newVersionScanner;
#endif
		public new void Dispose()
		{
			log.Stop();
			base.Dispose();
		}
	}
}
